/**
 * Created by lxl on 2017/2/13.
 */

layui.use('element', function(){
    var element = layui.element(); //导航的hover效果、二级菜单等功能，需要依赖element模块

    $(document).ready(function(){
        $.post("system/menu",function(data){
            $('.col-md-2').append('<ul class="layui-nav layui-nav-tree layui-nav-side" lay-filter="nav"></ul>') ;
            var key = "";
            $.each(data.param, function (i,val) {
                key = i ;
                $('.layui-nav').append('<li class="layui-nav-item layui-nav-itemed"><a href="javascript:;">'+ i + '</a><dl class="layui-nav-child" id=' + i +'> </dl>') ;
                if(isNotNull(val)){
                    $.each(val,function(i,val){
                        $('#'+key).append('<dd><a href="#" value=' + val + '>' + i +  '</a></dd>') ;
                    }) ;
                }
            }) ;
            element.init() ;
            element.on('nav(nav)',function(elem){
                if(isNotNull(elem.children().attr('value'))){
                    var height = $('.col-md-10').height() ;
                    var width = $('.col-md-10').width() ;
                    if(($('[lay-id='+elem.children().text()+']')).length!=0){
                        element.tabChange('tab',elem.children().text());
                    }else{
                        element.tabAdd('tab',{
                            title:elem.children().text(),
                            content:' <iframe src='+ elem.children().attr('value') + ' scrolling="no" width="100%" frameborder="0"></iframe>',
                            id:elem.children().text()
                        }) ;
                        element.tabChange('tab',elem.children().text());
                    }
                }
            }) ;
        }) ;

    }) ;
});



